##################################################
##Figure 3
##################################################

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
loadfonts()

data<-read.dta13("Figure3Data.dta")

cycle1<-data[,1]
cycle32<-data[,2]
cycle1b<-na.omit(cycle1)

pdf(file="Figure3.pdf", family="Bookman")

d1<-density(cycle1b)
d2<-density(cycle32)

plot(d1, main=" ", xlab="District Partisanship (Percent)", ylab="Density", col="gray30", lwd=1.5, ylim=c(0, .045), xlim=c(20, 100))
polygon(d1, col=alpha("gray50", .5), border=NA)

lines(d2, col="gray70", lwd=1.5)
polygon(d2, col=alpha("gray90", .45), border=NA)

text(90, .0435, expression(paste('KS'[italic('p')]*' < .001')), cex=1.2)

legend("topleft", cex=.98, legend=c('1956 Elections', '2018 Elections'), fill=c(alpha("gray50", .5), alpha("gray90", .45)), density=c(NA, NA), angle=c(NA, NA), border=c("black", "gray70"))

dev.off()
